package com.wzt.base.service.impl;

import com.wzt.base.service.IAutoAuditService;
import com.wzt.base.util.AjaxResponse;
import com.wzt.base.util.AutoAudit;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.Map;

/**
 * @author Zenith
 */
@Service
public class AutoAuditImpl implements IAutoAuditService {

    @Override
    public AjaxResponse audit(String text, String imgUrl, String videoUrl) {
        AjaxResponse response = AjaxResponse.oneResponse();
        StringBuilder sb = new StringBuilder();
        if (!StringUtils.isEmpty(text)) {
            Map<String, Object> textAuditResult =
                    AutoAudit.TextCensor(text);
            Boolean success = (Boolean) textAuditResult.get("success");
            String message = (String) textAuditResult.get("message");
            if (!success) {
                response.setSuccess(false);
                sb.append(text + ":" + message);
            }
        }

        if (!StringUtils.isEmpty(imgUrl)) {
            Map<String, Object> imgAuditResult =
                    AutoAudit.ImgCensor(imgUrl);
            Boolean success = (Boolean) imgAuditResult.get("success");
            String message = (String) imgAuditResult.get("message");
            if (!success) {
                response.setSuccess(false);
                sb.append(imgUrl + ":" + message);
            }
        }
        if (!StringUtils.isEmpty(videoUrl)) {
            //@TODO
        }

        if (!response.getSuccess()) {
            response.setMessage(sb.toString());
        }

        return response;
    }
}
